package main

import (
	"fmt"
	"math"
	"time"
)

func minSubArrayLen(s int, nums []int) int {
	n := len(nums)
	if n == 0 {
		return 0
	}
	ans := math.MaxInt32
	fmt.Println(ans)
	for i := 0; i < n; i++ {
		sum := 0
		for j := i; j < n; j++ {
			sum += nums[j]
			if sum >= s {
				ans = min(ans, j-i+1)
				break
			}
		}
	}
	if ans == math.MaxInt32 {
		return 0
	}
	return ans
}

func min(x, y int) int {
	if x < y {
		return x
	}
	return y
}

func main() {
	start := time.Now()
	target := 4
	nums := []int{1, 4, 4}
	result := minSubArrayLen(target, nums)
	cost := time.Since(start)
	fmt.Println("result:", result)
	fmt.Println(cost)
}
